home *** CD-ROM | disk | FTP | other *** search
/ SPACE 1 / SPACE - Library 1 - Volume 1.iso / program / 441 / dlibs12 / fread.c < prev    next >
C/C++ Source or Header  |  1990-11-23  |  622b  |  33 lines

  1. #include <osbind.h>
  2. #include <stdio.h>
  3. #include <errno.h>
  4.  
  5. int fread(data, size, count, fp)
  6.     register char *data;
  7.     int size;
  8.     int count;
  9.     register FILE *fp;
  10.     {
  11.     register long n, m, lsiz;
  12.     register int f, c;
  13.  
  14.     f = (fp->_flag &= ~_IORW);
  15.     lsiz = ((long) size);
  16.     n = ((long) count) * lsiz;
  17.     if(f & _IODEV)            /* device i/o */
  18.         {
  19.         for(m = 0; (m < n); ++m)
  20.             {
  21.             if((c = fgetc(fp)) == EOF)
  22.                 break;
  23.             *data++ = c;
  24.             } 
  25.         }
  26.     else                /* file i/o */
  27.         {
  28.         fflush(fp);            /* re-sync file pointers */
  29.         m = Fread(fp->_file, n, data);
  30.         }
  31.     return((m > 0) ? (m / lsiz) : (errno = ((int) m)));
  32.     }
  33.